home *** CD-ROM | disk | FTP | other *** search
/ NetNews Offline 2 / NetNews Offline Volume 2.iso / news / comp / lang / c++-part1 / 4967 < prev    next >
Encoding:
Text File  |  1996-08-06  |  1.4 KB  |  39 lines

  1. Path: news.clark.net!not-for-mail
  2. From: gusty@clark.net (Harlan Messinger)
  3. Newsgroups: comp.lang.c++
  4. Subject: Re: Argument from commandline???
  5. Date: 1 Feb 1996 22:20:57 GMT
  6. Organization: Clark Internet Services, Inc., Ellicott City, MD USA
  7. Message-ID: <4erec9$f88@clarknet.clark.net>
  8. References: <4eou36$p6g@prometheus.algonet.se>
  9. NNTP-Posting-Host: explorer.clark.net
  10. Mime-Version: 1.0
  11. Content-Type: TEXT/PLAIN; charset=ISO-8859-1
  12. Content-Transfer-Encoding: 8bit
  13. X-Newsreader: TIN [UNIX 1.3 950726BETA PL0]
  14.  
  15. Nylund Patrik (bifrost@algonet.se) wrote:
  16. : How do I include argument from the commandline to the main function in
  17. : a c++ program?
  18.  
  19.  
  20. The proper full definition of the function "main" is
  21.  
  22. int main(int argc, char *argv[]) {
  23.     ...
  24. }
  25.  
  26. The arguments argc and argv are available for use in your program. argc 
  27. is set to the number of words on your command line (words being strings 
  28. of non-whitespace characters separated by whitespace characters). For 
  29. example, if your command line has no arguments, argc will be 1, because 
  30. only the name of the program itself is on the command line.
  31.  
  32. argv[i] is an array of character pointers, defined for 0 <= i < argc, that
  33. point to copies of your command line arguments. The pointer argv[0] points
  34. to the name of the program as you invoked it, if your system makes that
  35. available. The command line arguments are then at argv[1], ..., argv[argc
  36. - 1]. 
  37.  
  38.